using System;
using System.Diagnostics;
using Microsoft.SharePoint;

namespace Sapphire.Linq.Framework
{
    public static class SPData
    {
        public static SPListItemCollection GetItems(this SPList list, SPQuery query)
        {
            var items = list.GetItems(query);
            Debug.WriteLine(string.Format("Getting items from list: {0}. Items count: {1}", list.Title, items.Count));
            return items;
        }

        public static SPListItem GetItem(SPList list, int lookupId)
        {
            Debug.WriteLine("Getting item " + lookupId + " from list: " + list.Title);
            return list.GetItemById(lookupId);
        }

        public static SPUser GetUser(SPWeb web, string value)
        {
            Debug.WriteLine("Getting user: " + value + " from web: " + web.Title);
            return new SPFieldUserValue(web, value).User;
        }

        public static SPList GetList(SPWeb web, string listUrl)
        {
            Debug.WriteLine("Getting list by url: " + listUrl);
            return web.GetListByUrl(listUrl);
        }

        public static SPList GetList(SPWeb web, Guid listId)
        {
            Debug.WriteLine("Getting list by id:" + listId);
            return web.Lists[listId];
        }
    }
}